#include <iostream>
using namespace std;

int gdb(int a, int b) { return b ? gdb(b, a % b) : a; }

int main()
{
    int n; cin >> n;
    while(n--)
    {
        int a, b; cin >> a >> b;
        cout << gdb(a, b) << endl;
    }
    return 0;
}